define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'bonus/rule/index' + location.search,
                    add_url: 'bonus/rule/add',
                    edit_url: 'bonus/rule/edit',
                    del_url: 'bonus/rule/del',
                    multi_url: 'bonus/rule/multi',
                    import_url: 'bonus/rule/import',
                    table: 'bonus_rule',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'bill_money', title: __('Bill_money'), operate: 'LIKE'},
                        {field: 'recom_rate1', title: __('Recom_rate1'), operate:'BETWEEN'},
                        {field: 'recom_rate2', title: __('Recom_rate2'), operate:'BETWEEN'},
                        {field: 'give_money1', title: __('Give_money1'), operate:'BETWEEN'},
                        {field: 'give_money2', title: __('Give_money2'), operate:'BETWEEN'},
                        {field: 'zhan_rate', title: __('Zhan_rate'), operate:'BETWEEN'},
                        {field: 'point_num', title: __('Point_num')},
                        {field: 'point_rate', title: __('Point_rate'), operate:'BETWEEN'},
                        {field: 'point_money', title: __('Point_money'), operate:'BETWEEN'},
                        {field: 'sign_money', title: __('Sign_money'), operate:'BETWEEN'},
                        {field: 'freeze_condition', title: __('Freeze_condition'), operate: 'LIKE'},
                        {field: 'tax_rate', title: __('Tax_rate'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status')},
                        {field: 'min_tf', title: __('Min_tf')},
                        {field: 'multiple_wd', title: __('Multiple_wd')},
                        {field: 'multiple_tf', title: __('Multiple_tf')},
                        {field: 'min_wd', title: __('Min_wd'), operate:'BETWEEN'},
                        {field: 'fee_wd', title: __('Fee_wd'), operate:'BETWEEN'},
                        {field: 'first_wd', title: __('First_wd'), operate:'BETWEEN'},
                        {field: 'fee_tf', title: __('Fee_tf'), operate:'BETWEEN'},
                        {field: 'fee_tf1', title: __('Fee_tf1'), operate:'BETWEEN'},
                        {field: 'wd_time', title: __('Wd_time'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
